package com.dididoctor.doctor.Activity.Usercentre.Evaluate;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Ui.PieChartView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by liying on 2016/4/20.
 */
public class EvaluateActivity extends EduActivity implements EvalutaeView {
    private PieChartView mPieChartView;
    private List<PieChartView.PieMember> datas = new ArrayList<PieChartView.PieMember>();
    private TextView mTvPercentage, mTvSatisfied, mTvCommonly, mTvDissatisfied;
    private EvalutePresenter mPresenter;
    private int mIntSatisfied, mIntCommonly, mIntDissatisfied, mIntTotal;

    @Override
    public void init() {
        mPieChartView = (PieChartView) findViewById(R.id.piechar);
        mTvPercentage = (TextView) findViewById(R.id.tv_percentage);
        mTvSatisfied = (TextView) findViewById(R.id.tv_satisfied);
        mTvCommonly = (TextView) findViewById(R.id.tv_commonly);
        mTvDissatisfied = (TextView) findViewById(R.id.tv_dissatisfied);
        mPresenter = new EvalutePresenter(EvaluateActivity.this, EvaluateActivity.this);
        mPresenter.getEvalutate();

    }

    @Override
    public void onClickEvent(View view) {

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_evaluate);
        ((TextView) findViewById(R.id.tv_title)).setText("我的评价");
    }


    @Override
    public void setData(String satisfied, String commonly, String dissatisfied) {

        PieChartView.PieMember member1 = new PieChartView.PieMember();
        member1.setColor(Color.parseColor("#fcb333"));

        PieChartView.PieMember member2 = new PieChartView.PieMember();
        member2.setColor(Color.parseColor("#fedd95"));


        PieChartView.PieMember member3 = new PieChartView.PieMember();
        member3.setColor(Color.parseColor("#cccccc"));


        mIntTotal = 0;
        mIntSatisfied = 0;
        mIntCommonly = 0;
        mIntDissatisfied = 0;

        if (satisfied != null && !"".equals(satisfied) &&!satisfied.equals("0")) {
            mTvSatisfied.setText("满意:" + satisfied + "人");
            mIntSatisfied = Integer.parseInt(satisfied);
            mIntTotal = mIntTotal + mIntSatisfied;
            member1.setNumber(mIntSatisfied);
        }

        if (commonly != null && !"".equals(commonly) ) {
            mTvCommonly.setText("一般:" + commonly + "人");
            mIntCommonly = Integer.parseInt(commonly);
            member2.setNumber(mIntCommonly);
            mIntTotal = mIntTotal + mIntCommonly;
        }

        if (dissatisfied != null && !"".equals(dissatisfied) &&!dissatisfied.equals("0")) {
            mIntDissatisfied = Integer.parseInt(dissatisfied);
            member3.setNumber(mIntDissatisfied);
            mTvDissatisfied.setText("不满意:" + dissatisfied + "人");
            mIntTotal = mIntTotal + mIntDissatisfied;
        }

        if (mIntSatisfied == 0 && mIntCommonly == 0 && mIntDissatisfied == 0) {
            mIntTotal = 100;
            mIntSatisfied = 100;
            member1.setNumber(100);
        }

        datas.add(member1);
        datas.add(member2);
        datas.add(member3);

        double perencet = ((double) mIntSatisfied / (double) mIntTotal) * 100;
        BigDecimal bg = new BigDecimal(perencet);
        double finalPerencet = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        mTvPercentage.setText(finalPerencet + "%");
        mPieChartView.setData(datas);

    }

}
